const {
    updateAllData
} = require("../dao/commonDao");

let proto = module.exports;


proto.roomDismissReason = {
    RDR_NONE: 0,
    /* 正常结束 */
    RDR_OWENER_ASK: 1,
    /* 未开始游戏,房主解散 */
    RDR_USER_ASK: 2,
    /* 游戏中,请求结束 */
    RDR_TIME_OUT: 4,
    /* 超时未响应 */
    RDR_NOT_ENOUGH_GOLD: 8,
    /* 房费不足*/
};

// 玩家状态
proto.userStatusEnum = {
    NONE: 0, //在线
    OFFLINE: 4, //离线
};

// 玩家状态
proto.userPlayEnum = {
    NONE: 0, //等待
    READY: 1, //准备
    PLAYING: 2, //游戏中
    WATCH: 5, //旁观
};


proto.USER_READY_NOTIFY = 301; // 用户准备的通知
proto.USER_READY_PUSH = 401; // 用户准备的推送
proto.userReadyPush = function (chairID, uid) {
    return {
        type: proto.USER_READY_PUSH,
        data: {
            chairID,
            uid
        }
    }
};


proto.OTHER_USER_ENTRY_ROOM_PUSH = 402; // 用户进入房间的推送
proto.otherUserEntryRoomPush = function (roomUserInfo, gameType) {
    return {
        type: proto.OTHER_USER_ENTRY_ROOM_PUSH,
        data: {
            roomUserInfo,
            gameType
        }
    }
};

proto.USER_LEAVE_ROOM_NOTIFY = 303; // 用户离开房间的通知
proto.USER_LEAVE_ROOM_RESPONSE = 403; // 用户离开房间的回复
proto.userLeaveRoomResponse = function (chairID, uid) {
    return {
        type: proto.USER_LEAVE_ROOM_RESPONSE,
        data: {
            chairID,
            uid
        }
    }
};


proto.USER_LEAVE_ROOM_PUSH = 404; // 用户离开房间推送
proto.userLeaveRoomPush = function (roomUserInfo, unionInfo) {
    return {
        type: proto.USER_LEAVE_ROOM_PUSH,
        data: {
            roomUserInfo: roomUserInfo,
            unionInfo: unionInfo,
        }
    }
};


proto.ROOM_DISMISS_PUSH = 405; // 房间解散的推送

proto.ROOM_USER_INFO_CHANGE_PUSH = 406; // 房间用户信息变化的推送

proto.USER_CHAT_NOTIFY = 307; // 用户聊天通知
proto.USER_CHAT_PUSH = 407; // 用户聊天推送

proto.USER_OFF_LINE_PUSH = 408; // 用户掉线的推送

proto.ROOM_DRAW_FINISHED_PUSH = 409; // 开设的房间局数用完推送

proto.ROOM_NOTICE_PUSH = 410; // 房间提示推送

proto.GAME_WIN_RATE_NOTIFY = 311;
proto.GAME_WIN_RATE_PUSH = 411;

proto.USER_RECONNECT_NOTIFY = 312; // 玩家断线重连
proto.USER_RECONNECT_PUSH = 412;

proto.ASK_FOR_DISMISS_NOTIFY = 313; // 玩家请求解散房间
proto.ASK_FOR_DISMISS_PUSH = 413;

proto.GAME_END_PUSH = 414; // 最终结果推送

proto.SORRY_I_WILL_WIN_NOTIFY = 415; // 对不起，这局我要赢

proto.ASK_FOR_DISMISS_STATUS_NOTIFY = 316; // 获取当前请求解散状态
proto.ASK_FOR_DISMISS_STATUS_PUSH = 416;

proto.GET_ROOM_SHOW_USER_INFO_NOTIFY = 317; // 获取房间需要显示的玩家信息通知
proto.GET_ROOM_SHOW_USER_INFO_PUSH = 417; // 获取房间需要显示的玩家信息推送

proto.GET_ROOM_SCENE_INFO_NOTIFY = 318; // 获取房间场景信息的通知
proto.GET_ROOM_SCENE_INFO_PUSH = 418; // 获取房间场景信息的推送

proto.GET_ROOM_ONLINE_USER_INFO_NOTIFY = 319; // 获取房间在线用户信息的通知
proto.GET_ROOM_ONLINE_USER_INFO_PUSH = 419; // 获取房间在线用户信息的推送

proto.USER_CHANGE_SEAT_NOTIFY = 320; // 换座通知
proto.USER_CHANGE_SEAT_PUSH = 420; // 换座推送

proto.BE_SHORT_OF_GOLD_COINS_PUSH = 421; // 换座金币不足推送

proto.USER_SIT_DOWN_NOTIFY = 322; // 玩家请求坐下
proto.USER_SIT_DOWN_PUSH = 422; // 玩家坐下推送

proto.ROOM_USER_SIT_DOWN_PUSH = 423; //房间中有玩家坐下


proto.EXIT_WAIT_SECOND = 30;
proto.NOANSWER_WAIT_SECOND = 120;
proto.ANSWER_EXIT_SECOND = 10;


proto.USER_GIFT_SEND_NOTIFY = 330; // 用户送礼物
proto.USER_GIFT_SEND_PUSH = 430; //用户送礼物

proto.USER_WATCH_PUSH = 431; // 用户旁观的推送

proto.ROOM_DISMISS_RESULT_PUSH = 432; // 房间解散结果推送

proto.USER_CAHRID_UPDATE_RESULT_PUSH = 433; // 玩家charid更新推送
proto.userCharUpdateResultPush = function (roomID, roomUserInfo) {
    return {
        type: proto.USER_CAHRID_UPDATE_RESULT_PUSH,
        data: {
            roomID,
            roomUserInfo
        }
    };
};

//玩家邀请推送
proto.GAME_INVITATION_NOTIFY = 380;
//玩家邀请结果
proto.GAME_INVITATION_RESUIL_PUSH = 480;
proto.gameInvitationResult = function (msg) {
    return {
        type: proto.GAME_INVITATION_RESUIL_PUSH,
        data: {
            msg
        }
    };
};

//玩家总输赢推送
proto.ROOM_USER_WIN_TOTAL_PUSH = 433;
proto.roomUserWinTotalPush = function (userWinTotalScore) {
    return {
        type: proto.ROOM_USER_WIN_TOTAL_PUSH,
        data: {
            userWinTotalScore
        }
    }
};


//玩家游戏状态推送
proto.USER_GAME_STATUS_PUSH = 440;
proto.getUserPlayeStatusPush = function (userPlayStatus) {
    return {
        type: this.USER_GAME_STATUS_PUSH,
        data: {
            userPlayStatus
        },
    };
};


//游戏状态推送
proto.GAME_STATUS_PUSH = 470;
proto.gameStatusPush = function (gameStatus, tick) {
    return {
        type: this.GAME_STATUS_PUSH,
        data: {
            gameStatus,
            tick
        },
    };
};



proto.roomUserSitDownPush = function (uid, chairID, roomUserInfo) {
    return {
        type: proto.ROOM_USER_SIT_DOWN_PUSH,
        data: {
            roomUserInfo,
            uid,
            chairID,
        }
    }
};


proto.selfEntryRoomPush = function (gameType, gameRule, roomID, gameData, userInfoArr, roomCreatorInfo) {

    let roomData = {
        gameType: gameType,
        gameRule: gameRule,
        roomID: roomID,
        gameData: gameData,
        userInfoArr: userInfoArr,
        roomCreatorInfo: roomCreatorInfo,
    }

    return {
        roomID: roomID,
        roomData: roomData,
    }
};

proto.roomMessagePush = function (msg) {
    return msg;
};

proto.userChatNotify = function (toChairID, msg) {
    return {
        type: proto.USER_CHAT_NOTIFY,
        data: {
            toChairID: toChairID,
            msg: msg,
        }
    };
};

proto.userChatPush = function (chairID, uid, type, msg, recipientID) {
    return {
        type: proto.USER_CHAT_PUSH,
        data: {
            chairID,
            uid,
            type,
            msg,
            recipientID
        },
    };
};

proto.userReadyNotify = function (isReady) {
    return {
        type: proto.USER_READY_NOTIFY,
        data: {
            isReady: isReady
        }
    }
};




//用户旁观的推送
proto.userWatchPush = function (chairID, userInfo) {
    return {
        type: proto.USER_WATCH_PUSH,
        data: {
            chairID,
            userInfo
        }
    }
};




proto.userLeaveRoomNotify = function () {
    return {
        type: proto.USER_LEAVE_ROOM_NOTIFY,
        data: {}
    }
};






proto.roomDismissPush = function (roomDismissReason) {
    return {
        type: proto.ROOM_DISMISS_PUSH,
        data: {
            reason: roomDismissReason,
        }
    };
};

proto.roomDismissResultPush = function () {
    return {
        type: proto.ROOM_DISMISS_RESULT_PUSH,
        data: {}
    };
};

proto.userInfoChangePush = function (changeInfo) {
    return {
        type: proto.ROOM_USER_INFO_CHANGE_PUSH,
        data: {
            changeInfo: changeInfo
        }
    }
};

proto.userOffLinePush = function (chairID, uid) {
    return {
        type: proto.USER_OFF_LINE_PUSH,
        data: {
            chairID: chairID,
            uid
        }
    }
};

proto.roomDrawFinished = function (allDrawScoreRecord) {
    return {
        type: proto.ROOM_DRAW_FINISHED_PUSH,
        data: {
            allDrawScoreRecord: allDrawScoreRecord
        }
    }
};

proto.getGameWinRateNotifyData = function (rate) {
    return {
        type: this.GAME_WIN_RATE_NOTIFY,
        data: {
            rate: rate
        }
    };
};

proto.getGameWinRatePushData = function () {
    return {
        type: this.GAME_WIN_RATE_PUSH,
        data: {}
    }
};

// 游戏规则格式
proto.getGameRule = function (bureau, isOwnerPay, memberCount, diamondCost, gameType, otherRule) {
    return {
        bureau: bureau, //局数
        isOwnerPay: isOwnerPay, //是否房主支付
        memberCount: memberCount, //房间人数
        diamondCost: diamondCost, //房卡
        gameType: gameType, //游戏类型
        otherRule: otherRule //游戏中特殊规则
    };
};

proto.getUserReconnectNotifyData = function () {
    return {
        type: this.USER_RECONNECT_NOTIFY,
        data: {}
    };
};

proto.getUserReconnectPushData = function (gameData) {
    return {
        type: this.USER_RECONNECT_PUSH,
        data: {
            gameData: gameData
        }
    };
};

proto.getAskForDismissNotifyData = function (isExit) {
    return {
        type: this.ASK_FOR_DISMISS_NOTIFY,
        data: {
            isExit: isExit
        }
    };
};

proto.getAskForDismissPushData = function (userList, tick) {
    return {
        type: this.ASK_FOR_DISMISS_PUSH,
        data: {
            userList,
            tick
        }
    };
};

// 游戏总结算推送
proto.getGameEndPushData = function (resout) {
    return {
        type: this.GAME_END_PUSH,
        data: {
            resout: resout
        }
    };
};

proto.getAskDismissStatusNotifyData = function () {
    return {
        type: this.ASK_FOR_DISMISS_STATUS_NOTIFY,
        data: {}
    };
};

proto.getAskDismissStatusPushData = function (isOnDismiss) {
    return {
        type: this.ASK_FOR_DISMISS_STATUS_PUSH,
        data: {
            isOnDismiss: isOnDismiss
        }
    };
};

proto.getRoomShowUserInfoNotify = function () {
    return {
        type: proto.GET_ROOM_SHOW_USER_INFO_NOTIFY,
        data: {}
    }
};

proto.getRoomShowUserInfoPush = function (selfUserInfo, shenSuanZiInfo, fuHaoUserInfoArr) {
    return {
        type: proto.GET_ROOM_SHOW_USER_INFO_PUSH,
        data: {
            selfUserInfo: selfUserInfo,
            shenSuanZiInfo: shenSuanZiInfo,
            fuHaoUserInfoArr: fuHaoUserInfoArr
        }
    }
};

proto.getRoomSceneInfoNotify = function () {
    return {
        type: proto.GET_ROOM_SCENE_INFO_NOTIFY,
        data: {}
    }
};

proto.getRoomSceneInfoPush = function (roomID, roomCreatorInfo, gameRule, roomUserInfoArr, gameData) {
    return {
        type: proto.GET_ROOM_SCENE_INFO_PUSH,
        data: {
            roomID: roomID,
            roomCreatorInfo: roomCreatorInfo,
            gameRule: gameRule,
            roomUserInfoArr: roomUserInfoArr,
            gameData: gameData
        }
    };
};

proto.getRoomOnlineUserInfoNotify = function () {
    return {
        type: proto.GET_ROOM_ONLINE_USER_INFO_NOTIFY,
        data: {}
    }
};

proto.getRoomOnlineUserInfoPush = function (shenSuanZiInfo, fuHaoUserInfoArr) {
    return {
        type: proto.GET_ROOM_ONLINE_USER_INFO_PUSH,
        data: {
            shenSuanZiInfo: shenSuanZiInfo,
            fuHaoUserInfoArr: fuHaoUserInfoArr
        }
    }
};

proto.getUserChangeSeatNotify = function (fromChairID, toChairID) {
    return {
        type: proto.USER_CHANGE_SEAT_NOTIFY,
        data: {
            fromChairID: fromChairID,
            toChairID: toChairID,
        }
    };
};

proto.getUserChangeSeatPush = function (fromChairID, toChairID, uid, userStatus, code = 0) {
    return {
        type: proto.USER_CHANGE_SEAT_PUSH,
        data: {
            fromChairID: fromChairID,
            toChairID: toChairID,
            uid: uid,
            userStatus: userStatus,
            code: code,
        }
    };
};

proto.getUserSitDownPush = function (uid, toChairID, userStatus, code = 0) {
    return {
        type: proto.USER_SIT_DOWN_PUSH,
        data: {
            toChairID: toChairID,
            uid: uid,
            userStatus: userStatus,
            code: code,
        }
    };
};

proto.beShortOfGoldCoinsPush = function (uid, userStatus) {
    return {
        type: proto.BE_SHORT_OF_GOLD_COINS_PUSH,
        data: {
            uid: uid,
            userStatus: userStatus,
        }
    };
};
proto.getUserGiftSendPush = function (fromChairID, toChairID, giftID) {
    return {
        type: proto.USER_GIFT_SEND_PUSH,
        data: {
            fromChairID,
            toChairID,
            giftID
        }
    };
};